from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-29 14:12:05.088860
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 29, Aug, 2021
Time: 14:12:09
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.8615
Nobs: 398.000 HQIC: -46.4059
Log likelihood: 4313.20 FPE: 4.91056e-21
AIC: -46.7630 Det(Omega_mle): 3.92769e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.435684 0.094710 4.600 0.000
L1.Burgenland 0.102980 0.048948 2.104 0.035
L1.Kärnten -0.115683 0.024335 -4.754 0.000
L1.Niederösterreich 0.159698 0.104966 1.521 0.128
L1.Oberösterreich 0.134849 0.103552 1.302 0.193
L1.Salzburg 0.281825 0.051296 5.494 0.000
L1.Steiermark 0.025389 0.067981 0.373 0.709
L1.Tirol 0.110210 0.053668 2.054 0.040
L1.Vorarlberg -0.115626 0.048563 -2.381 0.017
L1.Wien -0.012553 0.093451 -0.134 0.893
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.022132 0.220115 0.101 0.920
L1.Burgenland -0.044499 0.113759 -0.391 0.696
L1.Kärnten 0.036211 0.056556 0.640 0.522
L1.Niederösterreich -0.252333 0.243950 -1.034 0.301
L1.Oberösterreich 0.530605 0.240664 2.205 0.027
L1.Salzburg 0.311658 0.119216 2.614 0.009
L1.Steiermark 0.115218 0.157993 0.729 0.466
L1.Tirol 0.307207 0.124729 2.463 0.014
L1.Vorarlberg -0.008545 0.112864 -0.076 0.940
L1.Wien -0.006086 0.217188 -0.028 0.978
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.254564 0.048396 5.260 0.000
L1.Burgenland 0.087433 0.025012 3.496 0.000
L1.Kärnten -0.002343 0.012435 -0.188 0.851
L1.Niederösterreich 0.206549 0.053636 3.851 0.000
L1.Oberösterreich 0.171390 0.052914 3.239 0.001
L1.Salzburg 0.038063 0.026211 1.452 0.146
L1.Steiermark 0.017033 0.034737 0.490 0.624
L1.Tirol 0.062151 0.027423 2.266 0.023
L1.Vorarlberg 0.059473 0.024815 2.397 0.017
L1.Wien 0.106830 0.047752 2.237 0.025
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179858 0.047086 3.820 0.000
L1.Burgenland 0.046896 0.024335 1.927 0.054
L1.Kärnten -0.007310 0.012098 -0.604 0.546
L1.Niederösterreich 0.137066 0.052184 2.627 0.009
L1.Oberösterreich 0.317581 0.051481 6.169 0.000
L1.Salzburg 0.099069 0.025502 3.885 0.000
L1.Steiermark 0.134626 0.033797 3.983 0.000
L1.Tirol 0.076784 0.026681 2.878 0.004
L1.Vorarlberg 0.054064 0.024143 2.239 0.025
L1.Wien -0.038984 0.046460 -0.839 0.401
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209593 0.093769 2.235 0.025
L1.Burgenland -0.060826 0.048461 -1.255 0.209
L1.Kärnten -0.035571 0.024093 -1.476 0.140
L1.Niederösterreich 0.120079 0.103923 1.155 0.248
L1.Oberösterreich 0.174667 0.102523 1.704 0.088
L1.Salzburg 0.259193 0.050786 5.104 0.000
L1.Steiermark 0.079140 0.067305 1.176 0.240
L1.Tirol 0.123477 0.053134 2.324 0.020
L1.Vorarlberg 0.111496 0.048080 2.319 0.020
L1.Wien 0.022934 0.092522 0.248 0.804
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.025023 0.072969 0.343 0.732
L1.Burgenland 0.026276 0.037712 0.697 0.486
L1.Kärnten 0.050822 0.018749 2.711 0.007
L1.Niederösterreich 0.208191 0.080871 2.574 0.010
L1.Oberösterreich 0.340737 0.079781 4.271 0.000
L1.Salzburg 0.046561 0.039521 1.178 0.239
L1.Steiermark -0.001611 0.052376 -0.031 0.975
L1.Tirol 0.114162 0.041348 2.761 0.006
L1.Vorarlberg 0.061157 0.037415 1.635 0.102
L1.Wien 0.129886 0.071999 1.804 0.071
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190298 0.088922 2.140 0.032
L1.Burgenland 0.019713 0.045956 0.429 0.668
L1.Kärnten -0.057337 0.022848 -2.510 0.012
L1.Niederösterreich -0.138589 0.098550 -1.406 0.160
L1.Oberösterreich 0.199418 0.097223 2.051 0.040
L1.Salzburg 0.028930 0.048161 0.601 0.548
L1.Steiermark 0.303784 0.063826 4.760 0.000
L1.Tirol 0.491182 0.050388 9.748 0.000
L1.Vorarlberg 0.067824 0.045594 1.488 0.137
L1.Wien -0.102379 0.087739 -1.167 0.243
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160442 0.096872 1.656 0.098
L1.Burgenland -0.004280 0.050065 -0.085 0.932
L1.Kärnten 0.063246 0.024890 2.541 0.011
L1.Niederösterreich 0.199052 0.107361 1.854 0.064
L1.Oberösterreich -0.121148 0.105916 -1.144 0.253
L1.Salzburg 0.242546 0.052466 4.623 0.000
L1.Steiermark 0.153689 0.069532 2.210 0.027
L1.Tirol 0.050366 0.054893 0.918 0.359
L1.Vorarlberg 0.121380 0.049671 2.444 0.015
L1.Wien 0.137737 0.095584 1.441 0.150
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.487489 0.052518 9.282 0.000
L1.Burgenland -0.011778 0.027142 -0.434 0.664
L1.Kärnten -0.010368 0.013494 -0.768 0.442
L1.Niederösterreich 0.201488 0.058205 3.462 0.001
L1.Oberösterreich 0.261411 0.057421 4.553 0.000
L1.Salzburg 0.021451 0.028444 0.754 0.451
L1.Steiermark -0.024047 0.037696 -0.638 0.524
L1.Tirol 0.070025 0.029760 2.353 0.019
L1.Vorarlberg 0.058328 0.026929 2.166 0.030
L1.Wien -0.051177 0.051820 -0.988 0.323
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.018230 0.076771 0.134792 0.130260 0.043033 0.070021 0.003921 0.174420
Kärnten 0.018230 1.000000 -0.054839 0.128813 0.046921 0.069833 0.456496 -0.093764 0.095788
Niederösterreich 0.076771 -0.054839 1.000000 0.281844 0.081942 0.270713 0.014474 0.148679 0.247175
Oberösterreich 0.134792 0.128813 0.281844 1.000000 0.177346 0.287975 0.158963 0.115058 0.139407
Salzburg 0.130260 0.046921 0.081942 0.177346 1.000000 0.127211 0.055538 0.108318 0.050373
Steiermark 0.043033 0.069833 0.270713 0.287975 0.127211 1.000000 0.127586 0.087642 -0.024870
Tirol 0.070021 0.456496 0.014474 0.158963 0.055538 0.127586 1.000000 0.041895 0.117826
Vorarlberg 0.003921 -0.093764 0.148679 0.115058 0.108318 0.087642 0.041895 1.000000 -0.047089
Wien 0.174420 0.095788 0.247175 0.139407 0.050373 -0.024870 0.117826 -0.047089 1.000000